<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script>

$(function()
{
	$("#div_grid a[menu_id]").on("click", function()
	{
		var $this = $(this);
		var menuId = $this.attr("menu_id");
		if ($this.hasClass("am-icon-caret-down"))
		{
			$("#div_grid tr[parent_id=" + menuId +"]").hide();
			$(this).removeClass("am-icon-caret-down").addClass("am-icon-caret-right");
		}
		else if ($this.hasClass("am-icon-caret-right"))
		{
			$("#div_grid tr[parent_id=" + menuId +"]").show();
			$(this).removeClass("am-icon-caret-right").addClass("am-icon-caret-down");
		}
	});
	
});

function search_click()
{
	var obj = $.getObject("#div_search");	
	$("#div_grid").simpleLoad("/base/core/area_list", obj, 0);
	
}




</script>

<div class="am-g am-cf am-margin-top am-margin-bottom">
	<div class="am-u-sm-3 am-padding-right-0">
		<div class="am-btn-group">
			<a href="${path}/base/core/area_get" class="am-btn am-btn-primary am-radius">添加</a>
			<a class="am-btn am-btn-default" href="javascript:void(0)" onclick="blue_refresh_click('/base/core/area_refresh')">刷新缓存</a>
		</div>
	</div>
	<div class="am-u-sm-9 am-form-inline" id="div_search">
	</div>
</div>

<div class="am-g" id="div_grid">
	<div class="am-u-sm-12">
		<table class="am-table am-table-striped am-table-hover">
			<thead>
			<tr>
				<th width="300">名称</th>
				<th width="100">代码</th>
				<th width="100">车牌代码</th>
				<th width="100">状态</th>
				<th width="250">操作</th>
			</tr>
			</thead>
			<tbody>
			<#if treeList?? && treeList?size &gt; 0>
			<@tree map=treeList key="0" />
			</#if>
			</tbody>
		</table>
	</div>
</div>

<#macro tree map key count=0>
	<#assign voList=map[key]! />
	
	<#if voList??>
	<#list voList as vo>
			<tr id="tr_${vo.id}" parent_id="${vo.parentId!}" <#if count &gt; 0>style="display: none;"</#if>>
				<td class="am-text-truncate" title="${vo.name!}">
					<span style="padding-left: ${count*3}rem;">
						<#if map[vo.id?string]?? && map[vo.id?string]?size &gt; 0>
						<a href="javascript:void(0)" menu_id="${vo.id}" class="am-icon-caret-right am-icon-fw am-icon-sm"></a>
						</#if>
						${vo.name!}
					</span>
				</td>
				<td>${vo.id!}</td>
				<td>${vo.carCode!}</td>
				<td>${vo.stateName!}</td>
				<td>
					<div class="am-btn-group">
						<a href="${path}/base/core/area_get?id=${vo.id}" class="am-btn am-btn-primary am-btn-sm am-radius">编辑</a>
						<a href="${path}/base/core/area_get?parentId=${vo.id}" class="am-btn am-btn-danger am-btn-sm am-radius">子区域</a>
					</div>
				</td>
			</tr>
			<@tree map=map key=vo.id?string count=count+1 />
	</#list>
	</#if>
	
</#macro>

<#include "/layout/footer.ftl" />